<?php
/**
 * 商品分类控制器
 */
Class CategoryAction extends CommonAction {

	/**
	 * 分类列表视图
	 */
	Public function index () {
		$result = M('category')->select();
		// p($result);die;
		$cate = recursion($result, 0, 3, 31);
		p($cate);
		$this->cate = $cate;
		$this->display();
	}

	/**
	 * 添加顶级分类
	 */
	Public function addTopCate () {
		$this->display();
	}

	/**
	 * 添加子级分类
	 */
	Public function addCate () {
		$type = M('type')->select();
		$this->type = $type;
		$this->display();
	}

	/**
	 * 添加分类操作
	 */
	Public function runAddCate () {
		$data = array(
			'name' => $_POST['name'],
			'pid' => isset($_POST['pid']) ? (int) $_POST['pid'] : 0,
			'tid' => isset($_POST['tid']) ? (int) $_POST['tid'] : 0,
			);
		if (M('category')->data($data)->add()) {
			$this->success('添加成功', U('index'));
		} else {
			$this->error('添加失败');
		}
	}
}
?>